﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;

namespace Assistant.Controllers
{
    public class RequestResult
    {

        /// <summary>
        /// 出错返回码，为0表示成功，非0表示调用失败
        /// </summary>
        public int errcode { get; set; }

        /// <summary>
        /// 返回码提示语
        /// </summary>
        public string errmsg { get; set; }

        /// <summary>
        /// 获取枚举项描述信息 例如GetEnumDesc(Days.Sunday)
        /// </summary>
        /// <param name="en">枚举项 如Days.Sunday</param>
        /// <returns></returns>
        public static string GetEnumDesc(Enum en)
        {
            Type type = en.GetType();
            MemberInfo[] memInfo = type.GetMember(en.ToString());
            if (memInfo != null && memInfo.Length > 0)
            {
                object[] attrs = memInfo[0].GetCustomAttributes(typeof(DescriptionAttribute), false);
                if (attrs != null && attrs.Length > 0)
                {
                    return ((DescriptionAttribute)attrs[0]).Description;
                }
            }
            return en.ToString();
        }
    }

    public enum ErrorCode
    {
        [Description("成功")]
        Success = 0,

        [Description("未知错误")]
        Failed = 1,

        [Description("服务不可用")]
        NoService = 2,

        [Description("未知方法")]
        UnsupportedMethod = 3,

        [Description("不存在模型，请联系开发者添加")]
        InvalidParameter = 4,

        [Description("读取配置文件出错")]
        ReadConfigFailed = 5,

        [Description("数据库连接出错")]
        DBConectionFailed = 6
    }

   
}
